<?php
/**
 * Created by PhpStorm.
 * User: dust2
 * Date: 15-1-2
 * Time: 下午3:18
 */

/**
 * 订单表模型
 * Class Order
 */
class Order extends Eloquent
{
    protected  $table = 'orders';

    protected $guarded = array('id');

//    /**
//     * 获取某一订单的商品列表
//     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
//     */
//    public function products()
//    {
//        return $this->belongsToMany('Product', 'order_product', 'order_id', 'product_id');
//    }

    public static function getOrdersInfo($user_id, $columns)
    {
        return Order::where('user_id', $user_id)
            ->leftJoin('orderStatus', 'orders.status_id', '=', 'orderStatus.id')
            ->select($columns)
            ->orderBy('created_at', 'desc')
            ->get()
            ->toArray();
    }

    public static function getOrderProducts($order_id, $columns)
    {
        return OrderProduct::where('order_id', $order_id)
            ->join('products', 'order_product.product_id', '=', 'products.id')
            ->select($columns)
            ->get()
            ->toArray();
    }
}
